<%@page import="org.durcframework.core.UserContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>用户登录</title>
<script type="text/javascript" src="${res}js/MD5.js"></script>
</head>
<body>
<c:choose>
<c:when test="<%=UserContext.getInstance().getUser() != null %>">
	<script type="text/javascript">window.location = 'main.jsp';</script>
</c:when>
<c:otherwise>
	
	<div id="crudWin" style="display: none;">
		<form id="form">
	   		<table class="insert-tab" width="100%">
	   			<caption><span id="frm_msg" class="error"></span></caption>
	        	<tbody>
	                <tr>
	                    <th><s>*</s>用户名：</th>
	                    <td id="txtUsername"><input id="username" name="username" type="text"
	                    msgId="frm_msg"
	                    rules="[{rule:{notNull:true},errorMsg:'请输入用户名',successClass:''}
							]"
	                    /></td>
	                </tr>
	                <tr>
	                    <th><s>*</s>密码：</th>
	                    <td id="txtPassword"><input name="password" type="password"
	                    msgId="frm_msg"
	                    rules="[{rule:{notNull:true},errorMsg:'请输入密码',successClass:''}
							]"
	                    /></td>
	                </tr>
	         	</tbody>
	         </table>
         </form>
   </div>
	<script type="text/javascript">
	VUI.use(['Dialog','Msg','Form'], function() {
		
		var dlg,frm;
		
		frm = new VUI.Form({
			formId:'form'
		});
		
		dlg =  new VUI.Dialog({
			contentId:'crudWin'
			,title:'用户登录'
			,width:400
			,modal:false
			,closable:false
			,draggable:false
			,noCancelBtn:true
			,shadow:false
			,okText:'登录'
			,onOk:function() {
				login();
			}
		});
		
		dlg.show();
		
		function login() {
			frm.submit({
				url:'login.do'
				,onSubmit: function(data){
					var ret = this.validate();	// 返回false终止表单提交
					if(ret) {
						var password = data.password;
						data.password = faultylabs.MD5(password);
					}
					return this.check();	// 返回false终止表单提交
				}
				,success: function(result){
					if (result && result.success) {
						top.location = 'main.jsp';
					} else {
						var errorMsg = result.message;
						$('#frm_msg').text(errorMsg);
					}
				}
			});
		}
		
		$('#username').focus();
	});
	</script>
	
			
	</c:otherwise>
</c:choose>
</body>
</html>
